import radix
from cStringIO import StringIO

class PrefixToAS:
	"""A class used for prefix to as translating"""
	def __init__(self, filename = 'PrefixToAS.map'):
		self.radix = radix.Radix()
		doc_string = open(filename).read()
		doc = StringIO(doc_string)
		for line in doc:
        		arr = line.split('|')
        		node = self.radix.add(arr[1])
        		node.data.update({'as':arr[2]})
	def search(self, ip):
		node = self.radix.search_best(ip)
		if node == None:
			return None
		return node.data['as']
